package www.com.library.util;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.StateListDrawable;
import android.support.v4.content.ContextCompat;

/**
 * 根据状态返回图片资源集合
 * Created by reeta.zou on 2017/5/18.
 */

public class StateListUtil {

    public static StateListDrawable getDrawList(Context context, int normalImage, int selectImage){
        StateListDrawable drawable=new StateListDrawable();
        //如果要设置莫项为false，在前面加负号 ，比如android.R.attr.state_focesed标志true，-android.R.attr.state_focesed就标志false
        drawable.addState(new int[]{android.R.attr.state_focused}, ContextCompat.getDrawable(context,selectImage));
        drawable.addState(new int[]{android.R.attr.state_pressed}, ContextCompat.getDrawable(context,selectImage));
        drawable.addState(new int[]{android.R.attr.state_selected}, ContextCompat.getDrawable(context,selectImage));
        drawable.addState(new int[]{}, ContextCompat.getDrawable(context,normalImage));//默认

        return drawable;
    }

//    public static ColorStateList getColorList(Context context, int normalColor, int selectColor){
//        int[][] states , int[] colors
//        ColorStateList colorStateList=new ColorStateList();
//        //如果要设置莫项为false，在前面加负号 ，比如android.R.attr.state_focesed标志true，-android.R.attr.state_focesed就标志false
//        colorStateList.(new int[]{android.R.attr.state_focused}, ContextCompat.getColor(context,selectColor));
//        colorStateList.addState(new int[]{android.R.attr.state_pressed}, ContextCompat.getColor(context,selectColor));
//        colorStateList.addState(new int[]{android.R.attr.state_selected}, ContextCompat.getColor(context,selectColor));
//        colorStateList.addState(new int[]{}, ContextCompat.getColor(context,normalColor));//默认

//        return colorStateList;
//    }
}
